function Pagination(element, current, total, className) {
    this.element = element;
    this.current = current;
    this.total = total;
    this.className = className;

}
Pagination.prototype.show =  function(){
    this.element.html('');
    this.element.append(this.getPageCommon());
    this.bind_action();
};

Pagination.prototype.init = function () {
    if(this.total>1){
        this.show();
    }

};
Pagination.prototype.bind_action = function () {
    var self = this;
    $('.pageination a').click(function () {
        var number = $(this).data('number');
        if (number !== self.current) {
            self.current = number;
            self.show();
            self.action(number);
        }
    });
    $('#nextPage').click(function () {
        self.nextPage()
    })
    $('#perPage').click(function () {
        self.prePage()

    });
};
Pagination.prototype.action = function (page) {
    // console.log(page)
};

Pagination.prototype.prePage = function () {
    if (this.current - 1 >= 1) {
        this.current -= 1;
        this.show();
        this.action(this.current);

    }
};

Pagination.prototype.nextPage = function () {
    if (this.current + 1 <= this.total) {
        this.current += 1;
        this.show();
        this.action(this.current);
    }
};

Pagination.prototype.getPageCommon = function () {
    var str = '<a data-number="'+ this.current+'" class="select-page">' + this.current + '</a>';

    function getAStr(number) {
        return '<a  data-number="' + number + '" class="unselect-page">' + number + '</a> '
    }

    for (var i = 1; i <= 3; i++) {
        if (this.current - i > 1) {
            str = getAStr(this.current - i) + str;
        }
        if (this.current + i < this.total) {
            str = str + ' ' + getAStr(this.current + i);
        }
    }

    if (this.current - 4 > 1) {
        str = '<div class = "more-point">' + '...' + '</div>'+ str;
    }

    if (this.current > 1) {
        str = '<div class="pre-page" id="perPage">上一页 </div>' + getAStr(1) + ' ' + str;
    }

    if (this.current + 4 < this.total) {
        str = str +'<div class = "more-point">' + '...' + '</div>';
    }

    if (this.current < this.total) {
        str = str + ' ' + getAStr(this.total) + '<div class="next-page" id="nextPage"> 下一页 </div>';
    }
    str = '<div class="pageination">' + str + '</div>';
    return str;
};


